package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;

import bean.JTextFieldValidator;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaFrase extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel panFrase;
	private JLabel lblDescripcion;
	private JLabel lblNivel;
	private JButton btnCancelar;
	private JLabel lblEncabezado;
	private JButton btnSalir;
	private JButton btnGuardar;
	private JComboBox cmbNivel;
	private JTextFieldValidator txtDescripcion;
	private JTextField txtCodigoFrase;
	private JLabel lblCodigoFrase;
	
	private static VentanaFrase instancia;

	public final static synchronized VentanaFrase getInstancia() {
		if (instancia == null)
			instancia = new VentanaFrase();
		return instancia;
	}

	public VentanaFrase() {
		super();
		initGUI();
		//actualizarTamanoDescripcion();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			setTitle("Registrar Frase");
			getContentPane().setBackground(new java.awt.Color(255,255,255));
			{
				panFrase = new JPanel();
				getContentPane().add(panFrase, BorderLayout.CENTER);
				panFrase.setLayout(null);
				panFrase.setBackground(new java.awt.Color(255,255,255));
				{
					lblCodigoFrase = new JLabel();
					panFrase.add(lblCodigoFrase);
					lblCodigoFrase.setText("Codigo");
					lblCodigoFrase.setBounds(38, 76, 61, 18);
					lblCodigoFrase.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					lblDescripcion = new JLabel();
					panFrase.add(lblDescripcion);
					lblDescripcion.setText("Descripcion");
					lblDescripcion.setBounds(38, 113, 73, 18);
					lblDescripcion.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					lblNivel = new JLabel();
					panFrase.add(lblNivel);
					lblNivel.setText("Nivel");
					lblNivel.setBounds(38, 152, 61, 18);
					lblNivel.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					txtCodigoFrase = new JTextField();
					panFrase.add(txtCodigoFrase);
					txtCodigoFrase.setBounds(126, 73, 100, 24);
					txtCodigoFrase.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					txtDescripcion = new JTextFieldValidator();
					panFrase.add(txtDescripcion);
					txtDescripcion.setBounds(126, 112, 142, 24);
					txtDescripcion.setFont(new java.awt.Font("SansSerif",0,12));
					//txtDescripcion.setMaximumSize(10);
				}
				{
					ComboBoxModel cmbNivelModel = 
						new DefaultComboBoxModel();
					cmbNivel = new JComboBox();
					panFrase.add(cmbNivel);
					cmbNivel.setModel(cmbNivelModel);
					cmbNivel.setBounds(126, 151, 100, 24);
					cmbNivel.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					btnGuardar = new JButton();
					panFrase.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(38, 202, 87, 27);
					btnGuardar.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					btnCancelar = new JButton();
					panFrase.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(137, 202, 87, 27);
					btnCancelar.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					btnSalir = new JButton();
					panFrase.add(btnSalir);
					btnSalir.setText("Salir");
					btnSalir.setBounds(237, 202, 87, 27);
					btnSalir.setFont(new java.awt.Font("SansSerif",0,12));
				}
				{
					lblEncabezado = new JLabel();
					panFrase.add(lblEncabezado);
					lblEncabezado.setText("RELLENE LOS SIGUIENTES CAMPOS");
					lblEncabezado.setBounds(38, 18, 255, 24);
					lblEncabezado.setFont(new java.awt.Font("SansSerif",0,12));
				}
			}
			pack();
			this.setSize(363, 294);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	public void addListener(ActionListener actionListener){
		this.btnGuardar.addActionListener(actionListener);
		this.btnCancelar.addActionListener(actionListener);
		this.btnSalir.addActionListener(actionListener);
		this.cmbNivel.addActionListener(actionListener);
	}
	
	public void setCodigoFrase(String codigo){
		this.txtCodigoFrase.setText(codigo);
	}
	
	public String getCodigoFrase(){
		return this.txtCodigoFrase.getText();
	}
	
	public String getDescripcion(){
		return this.txtDescripcion.getText();
	}
	
	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}
	
	public void cargarComboNivel(Vector<String> vector){
		ComboBoxModel cmbNivelModel = 
			new DefaultComboBoxModel(vector);
		cmbNivel.setModel(cmbNivelModel);
	}
	
	public String getNivel(){
		return cmbNivel.getSelectedItem().toString();
	}
	
	public void borrarDatos(){
		this.txtDescripcion.setText("");
	}
	
	public JComboBox getComboNivel(){
		return this.cmbNivel;
	}
	
	public void actualizarTamanoDescripcion(int tamano){
		this.txtDescripcion.setMaximaLongitud(tamano);
	}
	
	public int getTamanoDescripcion(){
		return this.txtDescripcion.getMaximaLongitud();
	}
	
	/*public void actualizarTamanoDescripcion(){
		this.txtDescripcion = new JTextFieldValidator(JTextFieldValidator.SOLO_LETRAS);
	}*/

}
